package com.gomtel.las.theme1;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.AlphaAnimation;

public class AnimationBackground extends View {
	
	private int num = 0;

	public AnimationBackground(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		initView();
	}

	public AnimationBackground(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		initView();
	}

	public AnimationBackground(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	public AnimationBackground(Context context) {
		super(context);
		initView();
	}

	private void initView() {
		
		setBackgroundResource(R.drawable.background);

		final Handler handler = new Handler(){
			public void handleMessage(android.os.Message msg) {
				int a = num % 2;
				AlphaAnimation alphaAnimation = new AlphaAnimation(a, 1 - a);
				alphaAnimation.setDuration(2000);
				startAnimation(alphaAnimation);
			};
		};
		handler.post(new Runnable() {
			@Override
			public void run() {
				num++;
				handler.sendEmptyMessage(0);
				handler.postDelayed(this, 2000);
				// invalidate();
			}
		});
	}
	
}
